using System;
using UnityEngine;

public class PersistenData
{
	public static Action<int> OnCoinChange;

	public static Action<int> OnLanguageChange;

	public static Action<bool> OnMusicChange;

	public static int Coin
	{
		get
		{
			return PlayerPrefs.GetInt("UserCoin", 0);
		}
		set
		{
			PlayerPrefs.SetInt("UserCoin", value);
			if (OnCoinChange != null)
			{
				OnCoinChange(value);
			}
		}
	}

	public static bool Sound
	{
		get
		{
			return PlayerPrefs.GetInt("Sound", 1) == 1;
		}
		set
		{
			PlayerPrefs.SetInt("Sound", value ? 1 : 0);
		}
	}

	public static bool Music
	{
		get
		{
			return PlayerPrefs.GetInt("Music", 1) == 1;
		}
		set
		{
			PlayerPrefs.SetInt("Music", value ? 1 : 0);
			if (OnMusicChange != null)
			{
				OnMusicChange(value);
			}
		}
	}

	public static int Language
	{
		get
		{
			return PlayerPrefs.GetInt("Language", 0);
		}
		set
		{
			PlayerPrefs.SetInt("Language", value);
			if (OnLanguageChange != null)
			{
				OnLanguageChange(value);
			}
		}
	}

	public static int HealPowerUps
	{
		get
		{
			return PlayerPrefs.GetInt("HealPowerUps", 3);
		}
		set
		{
			PlayerPrefs.SetInt("HealPowerUps", value);
		}
	}

	public static int ImmoPowerUps
	{
		get
		{
			return PlayerPrefs.GetInt("ImmoPowerUps", 3);
		}
		set
		{
			PlayerPrefs.SetInt("ImmoPowerUps", value);
		}
	}

	public static int FreezePowerUps
	{
		get
		{
			return PlayerPrefs.GetInt("FreezePowerUps", 3);
		}
		set
		{
			PlayerPrefs.SetInt("FreezePowerUps", value);
		}
	}

	public static DateTime DailyRewardDay
	{
		get
		{
			string @string = PlayerPrefs.GetString("DailyRewardDay", "1990:1:1:0");
			int year = int.Parse(@string.Split(':')[0]);
			int month = int.Parse(@string.Split(':')[1]);
			int day = int.Parse(@string.Split(':')[2]);
			return new DateTime(year, month, day);
		}
	}

	public static int DailyRewardProgress
	{
		get
		{
			string @string = PlayerPrefs.GetString("DailyRewardDay", "1990:1:1:-1");
			return int.Parse(@string.Split(':')[3]);
		}
	}

	private static string[] UnlockedItemData
	{
		get
		{
			return PlayerPrefs.GetString("UnlockedItemData", string.Empty).Split(':');
		}
		set
		{
			string value2 = string.Join(":", value);
			PlayerPrefs.SetString("UnlockedItemData", value2);
		}
	}

	public static int UsingWeapon
	{
		get
		{
			return PlayerPrefs.GetInt("UsingWeapon", -1);
		}
		private set
		{
			PlayerPrefs.SetInt("UsingWeapon", value);
		}
	}

	public static void SaveRewardProgress(int saveProg)
	{
		string text = $"{DateTime.Now.Year}:{DateTime.Now.Month}:{DateTime.Now.Day}:{saveProg}";
		UnityEngine.Debug.Log(text);
		PlayerPrefs.SetString("DailyRewardDay", text);
	}

	public static bool checkHasItem(string value)
	{
		string[] unlockedItemData = UnlockedItemData;
		foreach (string text in unlockedItemData)
		{
			if (text.Equals(value))
			{
				return true;
			}
		}
		return false;
	}

	public static void addNewPurchaseData(string value)
	{
		if (!checkHasItem(value))
		{
			string[] unlockedItemData = UnlockedItemData;
			string[] array = new string[unlockedItemData.Length + 1];
			unlockedItemData.CopyTo(array, 0);
			array[array.Length - 1] = value;
			UnlockedItemData = array;
		}
	}

	public static void UseWeapon(int weaponID)
	{
		if (weaponID == -1)
		{
			StopUseWeapon();
			return;
		}
		string value = ShopItemType.Weapon + string.Empty + weaponID;
		if (checkHasItem(value))
		{
			UsingWeapon = weaponID;
		}
	}

	private static void StopUseWeapon()
	{
		UsingWeapon = -1;
	}
}
